package com.example.pinkcat.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.pinkcat.Fenqu_activity;
import com.example.pinkcat.R;
import com.example.pinkcat.activity.api.entity.VideoEntity;

import java.util.ArrayList;
import java.util.List;

public class Fenqu_RecyclerViewAdapter extends RecyclerView.Adapter<Fenqu_RecyclerViewAdapter.ViewHolder> {




    //图片资源
    int[] imageResourceID = new int[]{R.mipmap.fenqu_keji,R.mipmap.fenqu_zongyi,
            R.mipmap.fenqu_dianshiju,R.mipmap.fenqu_dianying,
            R.mipmap.fenqu_tity,R.mipmap.fenqu_meishi,
            R.mipmap.fenqu_fanju,R.mipmap.fenqu_wudao,
            R.mipmap.fenqu_youxi,R.mipmap.fenqu_qiche,
            R.mipmap.fenqu_yinyue,R.mipmap.fenqu_shenghuo,
            R.mipmap.fenqu_yule};
    private List<Integer> imageList = new ArrayList<>();
    //标题
    String[] mtitle = new String[]{
            "科技","综艺",
            "电视剧","电影",
            "体育","美食",
            "动漫","舞蹈",
            "游戏","汽车",
            "音乐","生活",
            "娱乐"};
    private List<String> titileList = new ArrayList<>();

    private Context context;

    public Fenqu_RecyclerViewAdapter(Context context){
        this.context = context;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        view = LayoutInflater.from(context).inflate(R.layout.layout_fenqu,parent,false);
        return new Fenqu_RecyclerViewAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        imageList.add(imageResourceID[position]);
        titileList.add(mtitle[position]);
        holder.tv.setText(titileList.get(position));
        Glide.with(context).load(imageList.get(position)).into(holder.img);
        holder.v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, Fenqu_activity.class);
                intent.putExtra("agreementTitle", mtitle[position]);
                context.startActivity(intent);
            }
        });


    }




    @Override
    public int getItemCount() {
        return mtitle.length;
    }

    @Override
    public int getItemViewType(int position) {
        return mtitle.length;
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private ImageView img;
        private TextView tv;

        private View v;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            img = itemView.findViewById(R.id.fenqu_list_img);
            tv = itemView.findViewById(R.id.fenqu_list_tv);
            v = itemView.findViewById(R.id.fenqu_list_RL);
        }
    }
}
